import sys
from confs import is_word

class Cache:
    def __init__(self):
        self.d = {}

    MAX_SIZE = 100000

    def emit(self, word, super_freq):
        self.d[word] = max(self.d.get(word, 0), super_freq)
        if len(self.d) > Cache.MAX_SIZE:
            self.flush()

    def flush(self):
        for word in self.d:
            print '%s\t:%d' % (word, self.d[word])
        self.d = {}

def main():
    '''
    input: words_all.txt
    (word, freq) -> (word, freq) if freq > 1
                    (sub-string-of-word, ':'freq)..  if freq > 1
    '''
    cache = Cache()
    for line in sys.stdin:
        line = line.strip()
        word, freq = line.split()
        freq = int(freq)
        if freq == 1:
            continue
        print line
        l = len(word)
        for i in range(l):
            for j in range(i + 1, l + 1):
                sub = word[i: j]
                if len(sub) < l and is_word(sub):
                    cache.emit(sub, freq)
    cache.flush()

if __name__ == '__main__':
    main()
